<h1><code ng:non-bindable="">filter</code>
<span class="hint">(filter in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><a href="http://github.com/angular/angular.js/edit/master/src/ng/filter/filter.js"
        class="improve-docs btn btn-primary">Improve this doc</a>

    <h2 id="Description">Description</h2>

    <div class="description">
        <div class="ng-filter-page ng-filter-filter-page"><p>Selects a subset of items from <code>array</code> and
            returns it as a new array.</p>

            <p>Note: This function is used to augment the <code>Array</code> type in Angular expressions. See
                <a href="api/ng.$filter"><code>ng.$filter</code></a> for more information about Angular arrays.</p>
        </div>
    </div>
    <h2 id="Usage">Usage</h2>

    <div class="usage"><h3 id="In.HTML.Template.Binding">In HTML Template Binding</h3>

        <div class="in-html-template-binding"><code ng:non-bindable="">{{ filter_expression | filter:expression
            }}</code>
        </div>
        <h3 id="In.JavaScript">In JavaScript</h3>

        <div class="in-javascript"><code ng:non-bindable="">$filter('filter')(array, expression)</code>
        </div>
        <h3 id="Parameters">Parameters</h3>
        <ul class="parameters">
            <li><code ng:non-bindable="">array – {Array} – </code>

                <div class="ng-filter-page ng-filter-filter-page"><p>The source array.</p></div>
            </li>
            <li><code ng:non-bindable="">expression – {string|Object|function()} – </code>

                <div class="ng-filter-page ng-filter-filter-page"><p>The predicate to be used for selecting items from
                    <code>array</code>.</p>

                    <p>Can be one of:</p>

                    <ul>
                        <li><p><code>string</code>: Predicate that results in a substring match using the value of
                            <code>expression</code>
                            string. All strings or objects with string properties in <code>array</code> that contain
                            this string
                            will be returned. The predicate can be negated by prefixing the string with <code>!</code>.
                        </p></li>
                        <li><p><code>Object</code>: A pattern object can be used to filter specific properties on
                            objects contained
                            by <code>array</code>. For example <code>{name:"M", phone:"1"}</code> predicate will return
                            an array of items
                            which have property <code>name</code> containing "M" and property <code>phone</code>
                            containing "1". A special
                            property name <code>$</code> can be used (as in <code>{$:"text"}</code>) to accept a match
                            against any
                            property of the object. That's equivalent to the simple substring match with a
                            <code>string</code>
                            as described above.</p></li>
                        <li><p><code>function</code>: A predicate function can be used to write arbitrary filters. The
                            function is
                            called for each element of <code>array</code>. The final result is an array of those
                            elements that
                            the predicate returned true for.</p></li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    <h2 id="Example">Example</h2>

    <div class="example">
        <div class="ng-filter-page ng-filter-filter-page"><h4>Source</h4>

            <div source-edit="" source-edit-deps="angular.js" source-edit-html="index.html-192" source-edit-css=""
                 source-edit-js="" source-edit-unit="" source-edit-scenario="scenario.js-193"></div>
            <div class="tabbable">
                <div class="tab-pane" title="index.html">
                    <pre class="prettyprint linenums" ng-set-text="index.html-192" ng-html-wrap=" angular.js"></pre>
                    <script type="text/ng-template" id="index.html-192">
                        <div ng-init="friends = [{name:'John', phone:'555-1276'},
                           {name:'Mary', phone:'800-BIG-MARY'},
                           {name:'Mike', phone:'555-4321'},
                           {name:'Adam', phone:'555-5678'},
                           {name:'Julie', phone:'555-8765'}]"></div>

                        Search: <input ng-model="searchText">
                        <table id="searchTextResults">
                            <tr>
                                <th>Name</th>
                                <th>Phone</th>
                            </tr>
                            <tr ng-repeat="friend in friends | filter:searchText">
                                <td>{{friend.name}}</td>
                                <td>{{friend.phone}}</td>
                            </tr>
                        </table>
                        <hr>
                        Any: <input ng-model="search.$"> <br>
                        Name only <input ng-model="search.name"><br>
                        Phone only <input ng-model="search.phone"><br>
                        <table id="searchObjResults">
                            <tr>
                                <th>Name</th>
                                <th>Phone</th>
                            </tr>
                            <tr ng-repeat="friend in friends | filter:search">
                                <td>{{friend.name}}</td>
                                <td>{{friend.phone}}</td>
                            </tr>
                        </table>
                    </script>
                </div>
                <div class="tab-pane" title="End to end test">
                    <pre class="prettyprint linenums" ng-set-text="scenario.js-193"></pre>
                    <script type="text/ng-template" id="scenario.js-193">
                        it('should search across all fields when filtering with a string', function() {
                        input('searchText').enter('m');
                        expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
                        toEqual(['Mary', 'Mike', 'Adam']);

                        input('searchText').enter('76');
                        expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')).
                        toEqual(['John', 'Julie']);
                        });

                        it('should search in specific fields when filtering with a predicate object', function() {
                        input('search.$').enter('i');
                        expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')).
                        toEqual(['Mary', 'Mike', 'Julie']);
                        });
                    </script>
                </div>
            </div>
            <h4>Demo</h4>

            <div class="well doc-example-live" ng-embed-app="" ng-set-html="index.html-192" ng-eval-javascript=""></div>
        </div>
    </div>
</div>
